package com.djq.hhc.controller;

import com.djq.hhc.holder.UserHolder;
import com.djq.hhc.result.Result;
import com.djq.hhc.service.UserFollowService;
import org.apache.catalina.User;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.HashMap;
import java.util.Map;

/**
 * Created with IntelliJ IDEA.
 *
 * @Author: dadd7
 * @Date: 2023/03/16/上午 9:27
 * @Description:
 */

@RestController
@RequestMapping(value = "/user/userFollow")
public class UserFollowController {

    @Autowired
    private UserFollowService userFollowService;

    //共同关注
    @GetMapping("common/{id}")
    public Result commonFollow (@PathVariable("id") Long userId) {
        return userFollowService.getCommonsFollow(userId);
    }

    //关注
    @PutMapping("/{id}/{isFollow}")
    public Result follow(@PathVariable("id") Long followUserId, @PathVariable("isFollow")
            Boolean isFollow) {
        return userFollowService.follow(followUserId, isFollow);
    }
    //取消关注
    @GetMapping("/or/not/{id}")
    public Result isFollow(@PathVariable("id") Long followUserId) {
        return userFollowService.isFollow(followUserId);
    }

    //自己的关注数量和粉丝数量
    @GetMapping("/followNum/{id}")
    public Result followNum(@PathVariable Long id) {
        Long follow = userFollowService.getFollowNum(id);
        Long fans = userFollowService.getFansNum(id);
        Map<String, Long> num = new HashMap<>();
        num.put("follow", follow);
        num.put("fans", fans);
        return Result.ok(num);
    }
}
